package com.nineclock.document.service.impl;

import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.document.dto.DocFileDto;
import com.nineclock.document.mapper.DocMapper;
import com.nineclock.document.pojo.DocFile;
import com.nineclock.document.service.DocService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DocServiceImpl implements DocService {
    @Autowired
    private DocMapper docMapper;

    @Override
    public void updateDocStatus(Long id, Short status) {
        //健壮性判断
        if (id == null || status == null) {
            throw new RuntimeException(ResponseEnum.INVALID_PARAM_ERROR.getMessage());
        }
        DocFile docFile = docMapper.selectById(id);
        if (docFile == null){
            throw new RuntimeException(ResponseEnum.FILE_NOT_FOUND.getMessage());
        }
        //更新封禁状态
        docFile.setStatus(status);
        //更新数据库
        docMapper.updateById(docFile);
    }
}
